package com.mob.commons;

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.network.KVPair;
import com.mob.tools.network.NetworkHelper.NetworkTimeOut;
import com.mob.tools.utils.DeviceHelper;
import com.mob.tools.utils.Hashon;
import com.mob.tools.utils.R;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class a
{
  private static HashMap<String, Object> a;
  private static long b;
  private static long c;
  private static boolean d;

  private static void a()
  {
    a = new HashMap();
    a.put("in", Integer.valueOf(1));
    a.put("all", Integer.valueOf(1));
    a.put("agap", "m");
    a.put("un", Integer.valueOf(1));
    a.put("rt", Integer.valueOf(1));
    a.put("rtsr", Integer.valueOf(300000));
    a.put("mi", Integer.valueOf(1));
    a.put("ext", Integer.valueOf(1));
    a.put("bs", Integer.valueOf(1));
    a.put("bsgap", Integer.valueOf(86400));
    a.put("di", Integer.valueOf(1));
    a.put("l", Integer.valueOf(0));
    a.put("lgap", Integer.valueOf(86400));
    a.put("wi", Integer.valueOf(1));
  }

  public static boolean a(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("mi"), Integer.valueOf(1))).intValue();
  }

  public static long b(Context paramContext)
  {
    r(paramContext);
    long l1 = SystemClock.elapsedRealtime();
    String str = String.valueOf(a.get("deviceTime"));
    try
    {
      long l3 = Long.valueOf(str).longValue();
      l2 = l3;
      return ((Long)R.forceCast(a.get("serverTime"), Long.valueOf(0L))).longValue() + (l1 - l2);
    }
    catch (Throwable localThrowable)
    {
      while (true)
        long l2 = 0L;
    }
  }

  private static long b(String paramString)
  {
    if (!TextUtils.isEmpty(paramString));
    switch (paramString.charAt(0))
    {
    default:
      return 0L;
    case 'h':
      return 3600L;
    case 'd':
      return 86400L;
    case 'w':
      return 604800L;
    case 'm':
    }
    return 2592000L;
  }

  private static void b(Context paramContext, boolean paramBoolean, Runnable paramRunnable)
  {
    j.a(new File(R.getCacheRoot(paramContext), "comm/locks/.ccLock"), paramBoolean, paramRunnable);
  }

  private static void c(String paramString)
  {
    try
    {
      a = new Hashon().fromJson(paramString);
      return;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
  }

  public static boolean c(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("rt"), Integer.valueOf(1))).intValue();
  }

  public static int d(Context paramContext)
  {
    r(paramContext);
    return ((Integer)R.forceCast(a.get("rtsr"), Integer.valueOf(300000))).intValue();
  }

  public static boolean e(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("all"), Integer.valueOf(1))).intValue();
  }

  public static long f(Context paramContext)
  {
    r(paramContext);
    return b((String)R.forceCast(a.get("agap"), "m"));
  }

  public static boolean g(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("di"), Integer.valueOf(1))).intValue();
  }

  public static boolean h(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("ext"), Integer.valueOf(1))).intValue();
  }

  public static boolean i(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("bs"), Integer.valueOf(1))).intValue();
  }

  public static int j(Context paramContext)
  {
    r(paramContext);
    return ((Integer)R.forceCast(a.get("bsgap"), Integer.valueOf(86400))).intValue();
  }

  public static boolean k(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("l"), Integer.valueOf(0))).intValue();
  }

  public static int l(Context paramContext)
  {
    r(paramContext);
    return ((Integer)R.forceCast(a.get("lgap"), Integer.valueOf(86400))).intValue();
  }

  public static boolean m(Context paramContext)
  {
    r(paramContext);
    return 1 == ((Integer)R.forceCast(a.get("wi"), Integer.valueOf(1))).intValue();
  }

  private static void r(Context paramContext)
  {
    try
    {
      long l = SystemClock.elapsedRealtime();
      if (a == null)
        b(paramContext, true, new b(paramContext, l));
      while (true)
      {
        return;
        if (l - b >= 60000L)
          b(paramContext, true, new c(paramContext, l));
      }
    }
    finally
    {
    }
  }

  private static boolean s(Context paramContext)
  {
    String str = w(paramContext);
    if (TextUtils.isEmpty(str))
    {
      a();
      return false;
    }
    c(str);
    x(paramContext);
    return true;
  }

  private static boolean t(Context paramContext)
  {
    String str = v(paramContext);
    if (TextUtils.isEmpty(str))
      return s(paramContext);
    c(str);
    if (((Long)R.forceCast(a.get("timestamp"), Long.valueOf(0L))).longValue() - c >= 86400000L)
      y(paramContext);
    return true;
  }

  private static File u(Context paramContext)
  {
    File localFile = new File(R.getCacheRoot(paramContext), "comm/dbs/.ccc");
    if (!localFile.getParentFile().exists())
      localFile.getParentFile().mkdirs();
    return localFile;
  }

  private static String v(Context paramContext)
  {
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      File localFile = u(paramContext);
      if (!localFile.getParentFile().exists())
        localFile.getParentFile().mkdirs();
      if (!localFile.exists())
        return null;
      FileInputStream localFileInputStream = new FileInputStream(localFile);
      byte[] arrayOfByte = new byte[1024];
      for (int i = localFileInputStream.read(arrayOfByte); i > 0; i = localFileInputStream.read(arrayOfByte))
        localByteArrayOutputStream.write(arrayOfByte, 0, i);
      localByteArrayOutputStream.close();
      localFileInputStream.close();
      str = new String(localByteArrayOutputStream.toByteArray(), "utf-8");
      return str;
    }
    catch (Throwable localThrowable)
    {
      while (true)
      {
        MobLog.getInstance().w(localThrowable);
        String str = null;
      }
    }
  }

  private static String w(Context paramContext)
  {
    String str1;
    Hashon localHashon;
    HashMap localHashMap1;
    try
    {
      f localf = f.a(paramContext);
      ArrayList localArrayList1 = localf.a();
      if (localArrayList1.isEmpty())
        return null;
      DeviceHelper localDeviceHelper = DeviceHelper.getInstance(paramContext);
      ArrayList localArrayList2 = new ArrayList();
      localArrayList2.add(new KVPair("appkey", ((MobProduct)localArrayList1.get(0)).getProductAppkey()));
      localArrayList2.add(new KVPair("plat", String.valueOf(localDeviceHelper.getPlatformCode())));
      localArrayList2.add(new KVPair("apppkg", localDeviceHelper.getPackageName()));
      localArrayList2.add(new KVPair("appver", localDeviceHelper.getAppVersionName()));
      localArrayList2.add(new KVPair("networktype", localDeviceHelper.getDetailNetworkTypeForStatic()));
      NetworkHelper.NetworkTimeOut localNetworkTimeOut = new NetworkHelper.NetworkTimeOut();
      localNetworkTimeOut.readTimout = 30000;
      localNetworkTimeOut.connectionTimeout = 30000;
      ArrayList localArrayList3 = new ArrayList();
      localArrayList3.add(new KVPair("User-Identity", localf.a(localArrayList1)));
      str1 = localf.httpGet("http://m.data.mob.com/cconf", localArrayList2, localArrayList3, localNetworkTimeOut);
      localHashon = new Hashon();
      localHashMap1 = localHashon.fromJson(str1);
      if (localHashMap1 == null)
        return null;
      if (!"200".equals(String.valueOf(localHashMap1.get("status"))))
        throw new Throwable("response is illegal: " + str1);
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
      return null;
    }
    HashMap localHashMap2 = (HashMap)R.forceCast(localHashMap1.get("switchs"));
    if (localHashMap2 == null)
      throw new Throwable("response is illegal: " + str1);
    long l = ((Long)R.forceCast(localHashMap1.get("timestamp"), Long.valueOf(0L))).longValue();
    localHashMap2.put("deviceTime", Long.valueOf(SystemClock.elapsedRealtime()));
    localHashMap2.put("serverTime", Long.valueOf(l));
    String str2 = localHashon.fromHashMap(localHashMap2);
    return str2;
  }

  private static void x(Context paramContext)
  {
    try
    {
      String str = new Hashon().fromHashMap(a);
      FileOutputStream localFileOutputStream = new FileOutputStream(u(paramContext));
      localFileOutputStream.write(str.getBytes("utf-8"));
      localFileOutputStream.flush();
      localFileOutputStream.close();
      return;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
  }

  private static void y(Context paramContext)
  {
    if (!d)
    {
      d = true;
      new d(paramContext).start();
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.commons.a
 * JD-Core Version:    0.6.2
 */